feat(Project): add MBR and hybrid volume schemas#329
Merged
Conversation
This adds the ability to accept MBR schemas to the Volume model. It's not fully tested yet but that's the next piece.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends Imagecraft’s project model to accept additional volume schemas (mbr and mbr,gpt hybrid) by refactoring the volume schema into a discriminated union of concrete volume/structure types, and adds tests/fixtures to validate the new parsing behavior.
Changes:
- Refactor
Volumeinto a discriminated union (GPTVolume,MBRVolume,HybridVolume) with schema-specificStructureItemtypes and validation. - Update GPT-only packing/image-creation codepaths to type against
GPTVolumewhile continuing to reject non-GPT schemas at image creation time. - Add unit + integration test coverage and new valid/invalid project fixtures for MBR and hybrid schemas; adjust YAML reference generation inputs.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/services/test_image.py | Update mocks to use GPT-specific structure item type. |
| tests/unit/pack/test_image.py | Switch volume parsing in tests to GPTVolume. |
| tests/unit/pack/test_grubutil.py | Switch volume parsing in tests to GPTVolume. |
| tests/unit/pack/test_gptutil.py | Switch volume parsing in tests to GPTVolume. |
| tests/unit/models/test_volume.py | Add extensive validation tests for MBR/hybrid and discriminated union behavior. |
| tests/unit/models/test_project.py | Add tests for partition-name generation across schema-specific structure items. |
| tests/integration/services/valid-projects/simple/imagecraft.yaml | Add a GPT-valid sample project for integration testing. |
| tests/integration/services/valid-projects/simple-mbr/imagecraft.yaml | Add an MBR-valid sample project for integration testing. |
| tests/integration/services/valid-projects/simple-hybrid/imagecraft.yaml | Add a hybrid-valid sample project for integration testing. |
| tests/integration/services/test_project.py | Add integration tests that load all valid/invalid project fixtures. |
| tests/integration/services/invalid-projects/mbr-unsupported-fields/imagecraft.yaml | Add invalid MBR fixture to ensure unsupported structure keys are rejected. |
| tests/integration/services/invalid-projects/mbr-unsupported-fields/error.txt | Expected error output for invalid MBR fixture. |
| tests/integration/services/invalid-projects/hybrid-unsupported-fields/imagecraft.yaml | Add invalid hybrid fixture to ensure unsupported structure keys are rejected. |
| tests/integration/services/invalid-projects/hybrid-unsupported-fields/error.txt | Expected error output for invalid hybrid fixture. |
| tests/integration/services/invalid-projects/gpt-unsupported-fields/imagecraft.yaml | Add invalid GPT fixture to ensure unsupported structure keys are rejected. |
| tests/integration/services/invalid-projects/gpt-unsupported-fields/error.txt | Expected error output for invalid GPT fixture. |
| tests/integration/conftest.py | Enable required craft-parts features for integration tests. |
| imagecraft/subprocesses.py | Capture stderr by default in the subprocess wrapper. |
| imagecraft/services/image.py | Cast GPT layouts to GPTVolume at the GPT-only image-creation callsite. |
| imagecraft/pack/gptutil.py | Type GPT utilities explicitly to GPTVolume; adjust partition JSON generation. |
| imagecraft/models/volume.py | Introduce schema-specific volume + structure item models and new schemas/roles. |
| imagecraft/models/init.py | Re-export GPT-specific models and update public model exports. |
| docs/reference/imagecraft-yaml.rst | Update kitbash-field references to GPT-specific model types. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Alex Lowe <alex.lowe@canonical.com>
tigarmo
approved these changes
Apr 24, 2026
smethnani
approved these changes
Apr 27, 2026
Signed-off-by: Alex Lowe <alex.lowe@canonical.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds the ability to accept projects with
mbrandmbr,gpt(hybrid) volume schemas. We don't implement this currently, we just accept projects that have it.IMAGECRAFT-111
make lint && make test.